package com.firefly.dao.assembler.ums;

import com.firefly.dao.dao.ums.po.MenuPo;
import com.firefly.dao.dto.ums.MenuDto;
import com.firefly.dao.dto.ums.MenuSortDto;
import com.firefly.dao.vo.ums.MenuTreeVo;
import com.firefly.dao.vo.ums.MenuVo;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 权限菜单数据类型转换
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/11/29
 **/
@Component
public class MenuAssembler {
    public List<MenuTreeVo> getTreeList(List<MenuPo> list) {
        List<MenuTreeVo> result = new ArrayList<>();
        list.forEach(item -> {
            MenuTreeVo tmp = new MenuTreeVo();
            tmp.setId(item.getId());
            tmp.setParentId(item.getParentId());
            tmp.setName(item.getName());
            tmp.setUrl(item.getUrl());
            tmp.setLabel(item.getLabel());
            tmp.setIcon(item.getIcon());
            tmp.setDisplay(item.getDisplay());
            tmp.setSort(item.getSort());
            result.add(tmp);
        });
        return result;
    }

    public MenuVo getVo(MenuPo entity) {
        MenuVo detail = new MenuVo();
        detail.setId(entity.getId());
        detail.setParentId(entity.getParentId());
        detail.setName(entity.getName());
        detail.setUrl(entity.getUrl());
        detail.setLabel(entity.getLabel());
        detail.setIcon(entity.getIcon());
        detail.setDisplay(entity.getDisplay());
        detail.setSort(entity.getSort());
        return detail;
    }

    public MenuPo getPo(MenuDto detail){
        MenuPo entity = new MenuPo();
        entity.setId(detail.getId());
        entity.setParentId(detail.getParentId());
        entity.setName(detail.getName());
        entity.setUrl(detail.getUrl());
        entity.setLabel(detail.getLabel());
        entity.setIcon(detail.getIcon());
        entity.setDisplay(detail.getDisplay());
        entity.setSort(detail.getSort());
        return entity;
    }

    public MenuPo getPo(MenuSortDto detail){
        MenuPo entity = new MenuPo();
        entity.setId(detail.getId());
        entity.setSort(detail.getSort());
        return entity;
    }
}
